package 笔试记录.百度二面;


import java.util.ArrayList;

public class Main2 {

    public static void main(String[] args){
        /*
        用例一：-1,-2,-3
        用例二：&,%,$
        用例三：1.0,2.0,3.0
        用例四：判断是否存在环（暂定）
        用例五：全角/半角情况下，针对另外一个请
         */
        //存在环
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);

        node1.next = node2;
        node2.next = node3;
        //node3.next = node1;
        reverse(node1);
        ListNode head = node1;
        while (head != null){
            System.out.print(head.val + " ");
            head = head.next;
        }
    }


    public  static boolean solve(ListNode head){
        ListNode slow = head;
        ListNode fast = head.next;
        if(slow.next == null || slow.next == null) return false;
        while(slow != null && fast != null && fast.next != null){
            if(fast == slow) return true;
            slow = slow.next;
            fast = fast.next.next;
        }
        return false;
    }

    public static void reverse(ListNode head){
        if(head == null) return;
        ArrayList<Integer> list = new ArrayList<>();
        ListNode head2 = head;
        while(head2 != null){
            list.add(head2.val);
            head2 = head2.next;
        }
        ListNode head3 = head;
        int index = list.size() - 1;
        while(head3 != null){
            head3.val = list.get(index);
            head3 = head3.next;
            index--;
        }
    }
}
